package com.dog.basics.netty.business.impl;
import cn.hutool.core.date.DateUtil;
import com.dog.basics.netty.business.IBusinessServer;
import com.dog.basics.netty.protobuf.dto.DogNewsContentDto;
import com.dog.basics.netty.util.NettyAttrUtil;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.log4j.Log4j2;

/**
 *  心跳消息
 */
@Log4j2
public class ResponseHandlerImplKeepAlive implements IBusinessServer<DogNewsContentDto.Message> {
    /**
     * @功能描述: 执行.心跳消息
     * @author He
     * @date 2020/7/13
     */
    @Override
    public void businessHandler(ChannelHandlerContext ctx,  DogNewsContentDto.Message msg) throws InterruptedException {
        log.info("心跳请求:{}", msg.toString());
        NettyAttrUtil.updateReaderTime(ctx.channel(), DateUtil.currentSeconds());

        ctx.channel().writeAndFlush(DogNewsContentDto.Message.newBuilder().setMsgType(msg.getMsgType()).setMsgCode(1));
    }
}